﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

namespace topicos2_oztech_drturin.Banco
{
    public class PacienteDB
    {
        ConexaoDB conx = new ConexaoDB();

        public Boolean ValidarLogin(String @cpf, String @senha) 
        {

            MySqlCommand cmd = conx.ComandoSP("procValidarLoginPaciente");
            
            cmd.Parameters.AddWithValue("_cpf", @cpf);
            cmd.Parameters.AddWithValue("_senha", @senha);            
            cmd.Connection.Open();
            MySqlDataReader mdr = cmd.ExecuteReader();
            Boolean flag = mdr.HasRows;
            cmd.Connection.Close();

            return flag;
        }

        public Boolean Cadastrar(String @nome, String @cpf, String @senha, int @permissao)
        {

            MySqlCommand cmd = conx.ComandoSP("procCadPac");

            cmd.Parameters.AddWithValue("_cpf", @cpf);
            cmd.Parameters.AddWithValue("_permissao", @permissao);
            cmd.Parameters.AddWithValue("_nome", @nome);
            cmd.Parameters.AddWithValue("_senha", @senha);
            cmd.Connection.Open();
            MySqlDataReader mdr = cmd.ExecuteReader();

            Boolean flag = false;
            if (mdr.RecordsAffected != 0) {flag = true;}
            
            cmd.Connection.Close();

            return flag;
        }
    }
}